
$(document).ready(function(){
    $('input[type="text"],input[type="password"]').keypress(function(e){
        if ( e.which == 13 ) {
            e.preventDefault();
            logar();
        } 
    });
        
    $('#logar').click(function(e){
        e.preventDefault();
        logar();
    });
    $('#username').focus();
});

function logar(){
    $.ajax({
        type: "POST",
        dataType: "json",
        url: base_adm+"login/login/autentica",
        data: {
            username: $('#username').val(), 
            password: $('#password').val()
        },
        success: function(a) {
            if(a.cod == 999){
                window.location.href=a.redirect;
            } else {
                alert(a.msg);
            }
        }
    });
}